package com.hewanglan.subject.infra.basic.utils;

import com.alibaba.druid.filter.config.ConfigTools;

public class DruidEncryptUtil {
    private static String privateKey;
    private static String publicKey;
    static {
        try {
            String[] keyPair = ConfigTools.genKeyPair(512);
            privateKey=keyPair[0];
            publicKey=keyPair[1];
            System.out.println("privateKey: "+privateKey);
            System.out.println("publicKey: "+publicKey);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public static String encrypt(String plainText)throws Exception{
        String encrypt = ConfigTools.encrypt(privateKey, plainText);
        System.out.println("encrypt: "+encrypt);
        return encrypt;
    }
    public static String decrypt(String encryptText)throws Exception{
        String decrypt = ConfigTools.decrypt(publicKey, encryptText);
        System.out.println("decrypt: "+decrypt);
        return decrypt;
    }

    public static void main(String[] args)throws Exception {
        String encrypt = encrypt("123456");
        String decrypt = decrypt(encrypt);
    }
}
